import { Direction } from '@/typings'
import { LIUDAO, THINK_DEED, NOTE, SYSUSER_UPDATE_INFO, SYSUSER_UPDATE_PWD, SYSUSER_REGISTER, SYSUSER_RESTPWD } from '@/store/modules/crud/keys'
import { CrudStates, CrudSearch, CrudState } from '@/store/modules/crud/typings'

const getDefaultSearch = (): CrudSearch => ({
  page: 0,
  size: 15,
  dir: Direction.ASC,
  sort: 'id',
  searchInfo: undefined,
  id: ''
})

const initState = (uri: string, defaultSearch?: CrudSearch): CrudState => {
  return {
    uri,
    search: defaultSearch || getDefaultSearch(),
    defaultSearch: defaultSearch || getDefaultSearch(),
    page: {
      content: [],
      number: 0,
      size: 0,
      totalElements: 0
    },
    dic: {},
    info: {},
    appd: {},
    isModify: false
  }
}

const state: CrudStates = {
  [LIUDAO]: initState('liudao'),
  [THINK_DEED]: initState('thinkDeed'),
  [NOTE]: initState('note'),
  [SYSUSER_UPDATE_INFO]: initState('sysUser/updatedInfo'),
  [SYSUSER_UPDATE_PWD]: initState('sysUser/updatedPwd'),
  [SYSUSER_REGISTER]: initState('sysUser/register'),
  [SYSUSER_RESTPWD]: initState('sysUser/restPwd')
}

export default state